#include "SpriteInfo.h"
#include "DirectXFramework.h"
#include <string>

void SpriteInfo::loadTexture(char * Filename)
{
	//manipulating argument FileName to add Folders then using
	//string.c_str() function to return string as char *
	//std::string sFile("./Assets/Sprite_Textures/" + std::string(Filename));
	////creating texture from file
	//HRESULT hr = D3DXCreateTextureFromFileEx(CDirectXFramework::Instance()->getDevice(),
	//	sFile.c_str(), 
	//	D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 0, 0, 
	//	D3DFMT_UNKNOWN, D3DPOOL_MANAGED, 
	//	D3DX_DEFAULT, D3DX_DEFAULT, 
	//	D3DCOLOR_XRGB(255, 0, 255), 
	//	&imageInfo, 0, &texture);

	D3DXCreateTextureFromFileEx(pdevice, L"deck-of-cards.png", 0, 0, 0, 0, 
		D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 
		D3DCOLOR_XRGB(255, 0, 255), &imageInfo, 0, &texture);

	//set sprite info's center based on loaded texture's width and height.
	height = imageInfo.Height;
	width = imageInfo.Width;
	setCenter();
}
/********SET FUNCTIONS**********/
void SpriteInfo::setCenter()
{
	center.X = width/2;
	center.Y = height/2;
}
void SpriteInfo::setPosOfCenter(float aX, float aY)
{
	posOfCenter.X = (int)aX;
	posOfCenter.Y = (int)aY;
}
void SpriteInfo::setScale(float xscale, float yscale)
{
	scale = xscale;
	scaleButton = yscale;
}

//update section pretty much for individual sprites checks if it is clicked within boundries
bool SpriteInfo::inSprite(POINT coord)
{
	if(coord.x <= posOfCenter.X + (int)((width*scale)/2) &&
		coord.x >= posOfCenter.X - (int)((width*scale)/2))
	{
		if(coord.y <= posOfCenter.Y + (int)((height*scale)/2) &&
			coord.y >= posOfCenter.Y - (int)((height*scale)/2))
		{
			return true;
		}
	}
	return false;
}

bool SpriteInfo::inSprite(XY coord)
{
	if(coord.X <= posOfCenter.X + (int)((width*scale)/2) &&
		coord.X >= posOfCenter.X - (int)((width*scale)/2))
	{
		if(coord.Y <= posOfCenter.Y + (int)((height*scale)/2) &&
			coord.Y >= posOfCenter.Y - (int)((height*scale)/2))
		{
			return true;
		}
	}
	return false;
}
SpriteInfo::SpriteInfo()
{
	height = 0;
	width = 0;
	//setup for button coordinates
	center;							//local coordinate
	posOfCenter;						//screen coordinate
	scale = 0;						//within set scale
	scaleButton = 0;					//button use
}